unit untListatemCargo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untListagemPadrao, StdCtrls, Buttons, ExtCtrls, DB, Grids,
  DBGrids;

type
  TfrmListagemCargo = class(TfrmListagemPadrao)
    procedure btnIncluirClick(Sender: TObject);
    procedure btnAlterarClick(Sender: TObject);
    procedure btnExcluirClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmListagemCargo: TfrmListagemCargo;

implementation

uses untCadCargo, UntDm;

{$R *.dfm}

procedure TfrmListagemCargo.btnIncluirClick(Sender: TObject);
begin
  inherited;
  frmCadCargo.Tag := 1;
  frmCadCargo.ShowModal;
end;

procedure TfrmListagemCargo.btnAlterarClick(Sender: TObject);
begin
  inherited;
  frmCadCargo.Tag := 2;
  frmCadCargo.ShowModal;
end;

procedure TfrmListagemCargo.btnExcluirClick(Sender: TObject);
begin
  inherited;


  // -----efetua a exclusao do registro_____________\\\\\\\\\\\\
  if DM.CDSCargo.RecordCount = 0 then
    Exit;
  try
    if MessageDlg('Deseja Excluir o Cargo?', mtConfirmation, [mbYes,mbNo],0) = mrYes then
    begin
      DM.SDSComando.CommandText := 'DELETE FROM "Cargo" WHERE COD_CARGO = :COD_CARGO';
      DM.SDSComando.Params.ParamByName('COD_CARGO').AsString := DM.CDSCargo.FieldByName('COD_CARGO').AsString;
      DM.SDSComando.ExecSQL();
      DM.CDSCargo.Close;
      DM.CDSCargo.Open;
    end;
  except
    if MessageDlg('Impossivel Excluir o Cargo', mtError, [mbOK],0) = mrOK then
      Exit;
  end;


end;

procedure TfrmListagemCargo.FormShow(Sender: TObject);
begin
  inherited;
  DM.CDSCargo.Open;
end;

procedure TfrmListagemCargo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  DM.CDSCargo.Close;
end;

end.
